package work20241216;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zdl
 * @date 2024/12/16
 */
public class Demo1 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(1,22);
        list.add(33);
        System.out.println(list);   //[11, 22, 33]
        list.remove(2);
        System.out.println(list);   //[11, 22]
        list.set(0,999);
        System.out.println(list);   //[999, 22]

        System.out.println(list.get(0));    //999
        System.out.println(list.contains(11));  //false
        System.out.println(list.contains(999)); //true
        System.out.println(list.isEmpty()); //false
        System.out.println(list.size()); //2
        List<Integer> list1 = new ArrayList<>();
        list1.add(66);
        list1.add(88);
        list.addAll(list1);
        System.out.println(list);   //[999, 22, 66, 88]
        list.set(1,66);
        list.removeAll(list1);
        System.out.println(list);   //[999]

        // 集合转数组
        Integer[] integers = new Integer[list.size()];
        Integer[] array = list.toArray(integers);
        System.out.println(Arrays.toString(array)); //[999]
        list.clear(); //清空数组
        System.out.println(list.isEmpty()); //true

    }

}
